//
//  MeatSearchShopViewController.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/31.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatSearchShopViewController.h"
#import "CustomScreenMenus.h"
#import "MeatMarketApi.h"
#import "MeatSearchHeader.h"
#import "MeatSearchTableViewCell.h"


@interface MeatSearchShopViewController ()

@property (nonatomic, strong) MeatMarketApi *meatApi;
@property (nonatomic, strong) BuyMeatadvertiseListModel *bannerModel;
@property (nonatomic, strong) BuyMeatListModel *listModel;
@property (nonatomic, strong) BuyMeatPartListModel *menuListModel;

@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) CustomScreenMenus *screenMenu;
@property (nonatomic, strong) MeatSearchHeader *header;


@end

@implementation MeatSearchShopViewController
#pragma mark - lifecycle methods
#pragma mark - init method

- (void)setupUI{
    
    self.view.backgroundColor = mBackgroudColor;
    
    [self.view addSubview:self.header];
    [self.view addSubview:self.screenMenu];
}


- (void)setupLayout{
    
    _screenMenu.mj_y = self.header.bottom;
    self.tableView.mj_y = _screenMenu.bottom;
    self.tableView.height = KScreenHeight - _screenMenu.bottom;
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}


#pragma mark - networking methods

//肉市-卖肉-广告
- (void)requestBuyMeatAdvertiseData {

    @weakify(self);
    [[self.meatApi getBuyMeatAdvertiseListData] subscribeNext:^(BuyMeatadvertiseListModel * _Nullable bannerModel) {

        @strongify(self);

    }error:^(NSError * _Nullable error) {

        @strongify(self);
        [self handlingError:error];
    }];
}

#pragma mark - response methods
#pragma mark - private methods


#pragma mark - tableview.delegate methods
#pragma mark - tableview.datasource methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 10;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 10;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [UIView makeViewBgColor:mBackgroudColor cornerRadius:0];
    view.frame = CGRectMake(0, 0, KScreenWidth, 10);
    return view;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MeatSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeatSearchTableViewCell"];
    
    cell.backgroundColor = KRedColor;
    return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"点击tableView");
}

#pragma mark - setter methods

#pragma mark - getter methods

- (void)registerTableViewCell{

    self.tableView.separatorColor = KClearColor;
    self.tableView.rowHeight = 227;
    [self.tableView registerClass:[MeatSearchTableViewCell class] forCellReuseIdentifier:@"MeatSearchTableViewCell"];
}


- (MeatMarketApi *)meatApi{
    
    if(!_meatApi){
        _meatApi = [[MeatMarketApi alloc]init];
    }
    return _meatApi;
}


- (CustomScreenMenus *)screenMenu{
    
    if (!_screenMenu) {
        
        _screenMenu = [[CustomScreenMenus alloc] init];
        _screenMenu.isHiddenNav = YES;
    }
    return _screenMenu;
}


- (MeatSearchHeader *)header{
    
    if (!_header) {
        _header = [[MeatSearchHeader alloc] init];
        
        @weakify(self);
        _header.leftNavBlock = ^{
            @strongify(self);
            [self.navigationController popViewControllerAnimated:YES];
            [self.screenMenu removeScreenView];
        };
    }
    return _header;
}


@end
